Event.observe ( window, 'load', bootstrap );

function bootstrap () {
  $( 'any_specification' ).on ( 'change', any_specification_changed );
  $( 'any_datasheet'     ).on ( 'change', any_datasheet_changed     );
}

function any_specification_changed () {
  var do_disable = $( 'any_specification' ).checked ? 1 : 0;
  
  $$( 'input.specification' ).each ( function ( node ) { do_disable ? disable ( node ) : enable ( node ) } );
}

function flip_all_specifications ( state ) {
  var checked = state == 'on' ? 'checked' : '';
  
  $$( 'input.specification' ).each ( function ( node ) { node.checked = checked; } );
}

function any_datasheet_changed () {
  var do_disable = $( 'any_datasheet' ).checked ? 1 : 0;
  
  $$( 'input.datasheet' ).each ( function ( node ) { do_disable ? disable ( node ) : enable ( node ) } );
}

function flip_all_datasheets ( state ) {
  var checked = state == 'on' ? 'checked' : '';
  
  $$( 'input.datasheet' ).each ( function ( node ) { node.checked = checked; } );
}
